package NetWork.Exercise001;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * ClassName:Client
 * Package:NetWork.Exercise001
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/7-22:41
 * @Version:v1.0
 */
public class Client {
    /*TCP通信练习
     * 客户端：多次发送数据
     * 服务端：接收多次数据,并打印*/
    public static void main(String[] args) throws IOException {

        //创建socket 对象并连接服务端
        Socket socket = new Socket("127.0.0.1", 1000);
        //写出数据
        Scanner sc = new Scanner(System.in);
        OutputStream os = socket.getOutputStream();
        while (true) {

            System.out.println("请输入您要发送的信息：");
            String str = sc.next();
            if ("886".equals(str)){
                break;
            }
            os.write(str.getBytes());


        }

        os.close();
        socket.close();

    }
}
